<?php
namespace App\Controllers\Admin;

use View,Input, Notification, Redirect, Sentry, Str,Work,Mount,Service;
use Auth, BaseController, Form,Aeconfig;

class IndexController extends BaseController {

	/**
	 * Display a listing of the resource.
	 * GET /admin/index
	 *
	 * @return Response
	 */
	public function index()
	{

//        $datas = Aeconfig::orderBy('id')->get()->toArray();
//        foreach($datas as $data){
//            $static[$data['title']] = $data;
//        }

        $user = Sentry::getUser();


        if ($user->hasAccess('admin')){
            $static['work'] = Work::count();
            $static['mount'] = Mount::where('state','>',0)->count();
            $static['customer'] = \Customer::where('type','>',0)->count();
            $static['user'] = \User::where('permissions','{"city":1}')->count()-1;
        }elseif($user->hasAccess('city')){
            $static['work'] = Work::where('city',$user->city)->count();
            $static['mount'] = Mount::where('city',$user->city)->count();
            $static['customer'] = \Customer::where('city',$user->city)->count();
            $static['user'] = \User::where('permissions','{"section":1}')->where('city',$user->city)->count();
        }elseif($user->hasAccess('section')){
            $static['subscribe'] = $user->subscribe;
            $static['work'] = Work::where('section_id',$user->area)->count();
            $static['mount'] = Mount::where('section_id',$user->area)->count();
            $static['service'] = Service::where('section_id',$user->area)->count();
//            $rates = Rate::where('area',$user->area)->orderBy('created_at', 'DESC')->paginate(20);
        }
        $METHOD = 'index';
        $ACTION = '';

        return View::make('admin.index.index',compact('METHOD','ACTION','static','user'));
//        return View::make('admin.index.index',compact('METHOD','ACTION'));
		//
	}

	/**
	 * Show the form for creating a new resource.
	 * GET /admin/index/create
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	/**
	 * Store a newly created resource in storage.
	 * POST /admin/index
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 * GET /admin/index/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 * GET /admin/index/{id}/edit
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 * PUT /admin/index/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 * DELETE /admin/index/{id}
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

}